package com.fuhe.chen.vendingmachine.controller.app;

import com.fuhe.chen.vendingmachine.dto.ApiResponseForList;
import com.fuhe.chen.vendingmachine.constant.MessageConstant;
import com.fuhe.chen.vendingmachine.pojo.Machine;
import com.fuhe.chen.vendingmachine.service.IMachineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/app/machineInfo")
@ResponseBody
@Api(tags = "机器信息接口(面向app)")
public class MachineInfoController {

    @Autowired
    IMachineService machineService;

    /**
     * 查询所有机器
     */
    @ApiOperation("查询所有机器列表")
    @GetMapping("/queryMachineList")
    @ResponseBody
    public ApiResponseForList<Machine> queryMachineList(){

        List<Machine> all = machineService.findAll();

        ApiResponseForList<Machine> response = new ApiResponseForList<>();
        response.setSuccess(true);
        response.setCode(MessageConstant.Success.SUCCESS_CODE);
        response.setMessage(MessageConstant.Success.QUERY_SUCCESS_MESSAGE);
        response.setData(all);

        return response;
    }
}
